<?php
  include_once('./queries/utils.inc.php');

  function job_History_Global_Job_Count($connection) {
    echo "Entered job_History_Global_Job_Count...";
    $sql = "SELECT count(*) " .
           "FROM history_horizontal h";
    
    echo $sql;
    return get_scalar(get_recordset($connection, $sql));

  }

  function job_History_Global_User_Count($connection) {
    echo "Entered job_History_Global_User_Count...";
    $sql = "SELECT count(distinct(h.owner)) " .
           "FROM history_horizontal h ";
    echo $sql;
    return get_scalar(get_recordset($connection, $sql));

  }  

  function job_History_By_User($connection, $index, $pn) { 
    $sql = "SELECT h.owner, count(*) " .
           "FROM Jobs_Horizontal_History h " .
           "GROUP BY h.owner " .
		"ORDER BY h.owner ";

    //echo $sql;
    //$raw_data = get_recordset($connection, $sql);

	$rcount = get_recordcount($connection, $sql);

    $sql = do_pagination_rewriting($pn, $rcount, $sql);

    //echo $index;
    unset($_SESSION["{$index}"]);
    $_SESSION["{$index}"] = array();
    $_SESSION["{$index}"]["title"] = "Job History by owner";
    $_SESSION["{$index}"]["message"] = "Job History by owner";

    $fields = array();
    $fields[0] = "Owner";
    $fields[1] = "Total jobs run";

    $rs = new recordset($rcount, $fields, get_recordset($connection, $sql));

	return $rs;
  }
?>
